package fragment;

import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.VideoView;

import com.example.administrator.projectmoudle_two.R;

/**
 * Created by eyesee on 2017/5/17.
 */

public class VideoViewFragment extends BaseFragment {

    private View mView;
    private VideoView mVideoView;

    private static final String path = "http://pgccdn.v.baidu.com/1138278353_3090739940_20170407124748.mp4?authorization=bce-auth-v1%2Fc308a72e7b874edd9115e4614e1d62f6%2F2017-04-07T04%3A48%3A00Z%2F-1%2F%2Fbcdd6d0e44ff4ceebb9e9be008006b779e207e2ed0e8899ae172ea0d3b36256a&responseCacheControl=max-age%3D8640000&responseExpires=Sun%2C+16+Jul+2017+12%3A48%3A00+GMT&xcode=8519ccd29f5d0f31d6c14a04c195bb449b4c8592998e0faf&time=1495105499&_=1495020447822";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mView = View.inflate(mContext, R.layout.fragment_videoview, null);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        initView(mView);
        playSet(mVideoView);
        return mView;
    }

    private void playSet(VideoView videoView) {
        Uri uri = Uri.parse(path);
        videoView.setVideoURI(uri);
        videoView.requestFocus();
        videoView.start();

        /**跳转到系统的视频播放器的过程*/
        /*String curPath = "这里传入视频路径";
        String pt = new File(curPath).getPath();
        Uri uri = Uri.parse("file://"+pt);
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(uri,"video/mp4");
        try{
            getActivity().startActivity(intent);
        }catch (Exception e){
            Toast.makeText(getActivity(), "没有默认播放器", Toast.LENGTH_SHORT).show();
            e.printStackTrace();
        }*/
    }

    private void initView(View view) {
        mVideoView = ((VideoView) view.findViewById(R.id.vv));
    }
}
